package com.baor.controller;

import com.baor.dao.UserDao;
import com.baor.domain.UserVo;
import com.baor.service.UserService;
import com.baor.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/userList")
    public AjaxResult<?> selectUserList(@RequestBody Map<String,Object> param){
        int pageindex = (int) param.get("pageIndex");
        int pagesize = (int) param.get("pageSize");
        param.put("pageIndex", (pageindex - 1) * pagesize);
        return userService.selectUserList(param);
    }

    @RequestMapping("/searchUserList")
    public AjaxResult<?> searchUserList(@RequestBody Map<String,Object> param){
        System.out.println(param);
        int pageindex = (int) param.get("pageIndex");
        int pagesize = (int) param.get("pageSize");
        param.put("pageIndex", (pageindex - 1) * pagesize);
        return userService.selectUserList(param);
    }

    @RequestMapping("insertUser")
    public AjaxResult<?> insertUser(@RequestBody Map<String,Object> params){
        return userService.insertUser(params);
    }

    @RequestMapping("roleList")
    public AjaxResult<?> roleList(){
        System.out.println("???????");
        return userService.roleList();
    }

    @RequestMapping("userInfo")
    public AjaxResult<?> userInfo(int userId){
        return userService.userInfo(userId);
    }

    @RequestMapping("updateUser")
    public AjaxResult<?> updateUser(@RequestBody Map<String,Object> param){
        return userService.updateUser(param);
    }

    @RequestMapping("delete")
    public AjaxResult<?> delete(int userId){
        return userService.delete(userId);
    }

    @RequestMapping("selectSuper")
    public AjaxResult<?> selectSuper(@RequestBody  Map<String,Object> params){
        return userService.selectSuper(params);
    }

    @RequestMapping("login")
    public AjaxResult<?> login(@RequestBody Map<String,Object> param){
        return userService.login(param);
    }

    @RequestMapping("logOut")
    public AjaxResult<?> logOut(String userAccount){
        return userService.logOut(userAccount);
    }
}
